<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ include file="/taglibs.jsp"%>
<%@page import="java.util.Date"%>
<s:url value="/js" var="jsPath"/>
<s:url value="/css" var="cssPath"/>
<s:url value="/images" var="imgPath"/>
<style type="text/css">
	.bg-active {
		background: #D4FAED;
	}
</style>
<!-- 月历 -->
<script type="text/javascript" charset="UTF-8" src="${jsPath}/jquery.datepick.js"></script>
<script type="text/javascript" charset="UTF-8" src="${jsPath}/jquery.datepick-zh-CN.js"></script>
<link rel="stylesheet" type="text/css" href="${cssPath}/smoothness.datepick.css" />
<!-- 時間 -->	
<script type="text/javascript" charset="UTF-8" src="${jsPath}/jquery-ui-1.7.2.custom.min.js"></script>
<link rel="stylesheet" type="text/css" href="${cssPath}/jquery-ui-1.7.2.custom.css"/>
<!-- ToolTip -->
<script src="${jsPath}/jquery.tooltip.js" type="text/javascript"></script>
<link rel="stylesheet" href="${cssPath}/jquery.tooltip.css" />
<script language="javascript">
	$().ready( function() {
		$('#paramStartDateTime').datepick({minDate: null, showOn: 'both', 
	    	buttonImageOnly: true, buttonImage: '${imgPath}/calendar.gif',numberOfMonths:2,dateFormat:"yy-mm-dd",yearRange: '-50:+50'});
		$('#paramEndDateTime').datepick({minDate: new Date(), showOn: 'both', 
	   	  buttonImageOnly: true, buttonImage: '${imgPath}/calendar.gif',numberOfMonths:2,beforeShow:customRange,dateFormat:"yy-mm-dd",yearRange: '-50:+50'});
	function customRange (){
		var startDt = $('#paramStartDateTime').val(); //起始日
		var endDt = new Date(parseInt(startDt.substring(0,4),10),parseInt(startDt.substring(5,7),10)-1,parseInt(startDt.substring(8,10),10)); //結束日
		return {minDate:endDt}; 
	}
	$("tr[id*='tr_tooltip']").tooltip();
	});	
</script>
<div style="color:red">
<s:actionerror />
<s:actionmessage />
<s:fielderror /></div>
<br />
<h1>行销活动管理
<div class="f-link">
<yaodian100:checkPermission permissions="GROUP_A-50-100-300,ROLE_MM">
<a href="add.do">新增</a>
</yaodian100:checkPermission>
<a href="#" onclick="document.formObj.submit();">搜寻</a>
</div>
</h1>

<s:form action="search.do" method="post" name="formObj">
<table width="850">
<tr>
	<td width="15%">活动类型：</td>
	<td>
	<s:select list="menuType" name="paramTypes" listValue="desc" headerKey="" headerValue="全部"/>
	</td>

	<td width="15%">Domain：</td>
	<td width="25%"><s:select name="paramDomain" list="menuDomain.options" headerKey="" headerValue="全部" listKey="key" listValue="value.name"/></td>
</tr>
<tr>
	<td width="15%">活动名称：</td>
	<td width="35%"><s:textfield name="paramName"/></td>
	<td width="15%">活动范围：</td>
	<td width="35%"><s:checkboxlist list="menuRange" name="paramRanges" listValue="desc"></s:checkboxlist></td>
</tr>
<tr>
	<td width="15%">活动时间：</td>
	<td width="35%">
	<input name="paramStartDateTime" id="paramStartDateTime" size="10" value="${paramStartDateTime}">
	~
	<input name="paramEndDateTime" id="paramEndDateTime" size="10" value="${paramEndDateTime}">
	</td>
	<td width="15%">启用：</td>
	<td width="35%"><s:checkboxlist list="#{'true':'是','false':'否'}" listKey="key" listValue="value" name="paramEnable"/></td>
</tr>
<%--
<tr>
	<td width="15%">渠道：</td>
	<td width="35%"><s:select name="paramCookie" list="menuChannel.options" headerKey="" headerValue="全部" listKey="key" listValue="value.name"/></td>
	<td width="15%">Domain：</td>
	<td width="35%"><s:select name="paramDomain" list="menuDomain.options" headerKey="" headerValue="全部" listKey="key" listValue="value.name"/></td>
</tr>
 --%>
</table>
</s:form>
<br/>
	<table class="tb-1" width="100%">
		<thead>
			<tr>
				<th>#</th>
				<th>行销活动名称</th>
				<th>範圍</th>
				<th>活动类型</th>
				<th>活动时间</th>
				<th>Domain</th><%--
				<th>渠道</th> --%>
				<th>启用</th>
			</tr>
		</thead>
<c-rt:set var="now" value="<%=new Date(System.currentTimeMillis())%>"/>
		<s:if test="campaignList.size > 0">
		<tbody>
			<c:forEach items="${campaignList}" var="campaign" varStatus="rows_index">
				<c-rt:set var="title" value=""/>
				<c:if test="${campaign.type == 'M01'}">
				<c:forEach items="${campaign.typeExtends}" var="extend">
				<c-rt:set var="title">${title}${extend.minOrderAmount} ~ ${extend.maxOrderAmount}：每${extend.minQty}元, 发放 ${extend.maxQty}点积分<br/></c-rt:set>
				</c:forEach>
				</c:if>
				<c:if test="${campaign.type == 'M02'}">
				<c-rt:set var="title">积分折抵比率：积分 ${campaign.offsetRate} = 1元<br/>积分折抵上限：订单金额${campaign.offsetUpperLimit}%<br/></c-rt:set>
				</c:if>
				<c:if test="${campaign.type == 'M03'}">
				<c-rt:set var="title">每日登入${campaign.loginCount}次，发送积分${campaign.giveBonus}点</c-rt:set>
				</c:if> 
				<tr class="${rows_index.count % 2 == 0 ? 'bg-yl' : ''}<c:if test="${activateCampaign.uuid == campaign.uuid}"> bg-active</c:if>" title="${title}" id="tr_tooltip">
					<td><fmt:formatNumber
						pattern="0000" value="${rows_index.count + pager.currentPage*20}" /></td>
					<td style="text-align: left"><a href="view.do?uuid=${campaign.uuid}" />${campaign.campaignName}</a></td>
					<td><c:out value="${campaign.range.desc}"/>
<c:if test="${campaign.range.code eq 'Category'}">
<br/><c:forEach items="${campaign.rangeExtIds}" var="extId" varStatus="stat">
<c:if test="${stat.index!=0}">,</c:if>${extId}</c:forEach></c:if>
</td>
					<td style="text-align: left"><c:out value="${campaign.type.desc}"/></td>
<c:set var="fontColor" value="block"/>
<c:if test="${campaign.startDateTime ge now}"><c:set var="fontColor" value="green"/></c:if>
<c:if test="${campaign.endDateTime le now}"><c:set var="fontColor" value="green"/></c:if>
					<td style="color:${fontColor}"><fmt:formatDate value="${campaign.startDateTime}"
						pattern="yyyy-MM-dd HH:mm" />~<fmt:formatDate value="${campaign.endDateTime}"
						pattern="yyyy-MM-dd HH:mm" /></td>
					<td>${menuDomain.options[campaign.domain].name}</td><%-- 
					<td>${menuChannel.options[campaign.cookie].name}</td>--%>
					<td><c:if test="${campaign.enable}">是</c:if><c:if test="${!campaign.enable}"><div style="color:green">否</div></c:if></td>
				</tr>
			</c:forEach>
		</tbody>
		</s:if>
		<s:else>
			<tbody>
				<tr class="bg-yl"><td colspan="6">查无资料!!</td></tr>
			</tbody>
		</s:else>
	</table>	
	<yaodian100:pageutil link="search.do" pagerObj="${pager}" />
